import { createRouter, createWebHashHistory } from 'vue-router'
import AdminLayout from '@/components/AdminLayout.vue'

const routes = [
  {
    path: '/',
    component: AdminLayout,
    redirect: '/user-management/list', // 用户管理作为主页面
    children: [
      // 用户管理 (主模块)
      {
        path: '/user-management',
        redirect: '/user-management/list',
        meta: { title: '用户管理', icon: 'UserFilled' },
        children: [
          {
            path: 'list',
            component: () => import('@/views/UserManagement/UserList.vue'),
            meta: { title: '用户列表', icon: 'List' }
          },
          {
            path: 'learning-progress',
            component: () => import('@/views/UserManagement/LearningProgress.vue'),
            meta: { title: '学习进度', icon: 'TrendCharts' }
          },
          {
            path: 'exam-record',
            component: () => import('@/views/UserManagement/UserExamRecord.vue'),
            meta: { title: '考试记录', icon: 'Notebook' }
          },
          {
            path: 'wrong-questions',
            component: () => import('@/views/UserManagement/UserWrongQuestionAnalysis.vue'),
            meta: { title: '错题分析', icon: 'Warning' }
          },
          {
            path: 'learning-plan',
            component: () => import('@/views/UserManagement/UserLearningPlan.vue'),
            meta: { title: '学习计划', icon: 'Calendar' }
          },
          {
           path:'question-collection',
           component: () => import('@/views/UserManagement/UserQuestionCollection.vue'),
           meta: { title: '题目收藏', icon: 'StarFilled' }
          }
        ]
      },

      // 题库管理 (二级菜单)
      {
        path: '/question-management',
        redirect: '/question-management/list',
        meta: { title: '题库管理', icon: 'Collection' },
        children: [
          {
            path: 'list',
            component: () => import('@/views/QuestionManagement/QuestionList.vue'),
            meta: { title: '题库列表', icon: 'List' }
          },
          {
            path: 'rolls',
            component: () => import('@/views/QuestionManagement/RollManagement.vue'),
            meta: { title: '套卷管理', icon: 'Files' }
          }
        ]
      },

      // 数据统计 (二级菜单)
      {
        path: '/statistics',
        redirect: '/statistics/overview',
        meta: { title: '数据统计', icon: 'Histogram' },
        children: [
          {
            path: 'overview',
            component: () => import('@/views/Statistics/Overview.vue'),
            meta: { title: '数据概览', icon: 'PieChart' }
          },
          {
            path: 'community',
            component: () => import('@/views/Statistics/CommunityAnalysis.vue'),
            meta: { title: '社区分析', icon: 'DataAnalysis' }
          },
          {
            path: 'reports',
            component: () => import('@/views/Statistics/Details.vue'),
            meta: { title: '业务报表', icon: 'DocumentCopy' }
          }
        ]
      },

      // 单页面模块
      {
        path: '/feedback',
        component: () => import('@/views/Feedback.vue'),
        meta: { title: '反馈处理', icon: 'ChatDotRound' }
      },
      {
        path: '/post-management',
        component: () => import('@/views/PostManagement.vue'),
        meta: { title: '帖子管理', icon: 'Document' }
      },
      // 在 routes 数组的 children 中添加以下内容
      {
        path: '/login-log',
        component: () => import('@/views/LoginLog.vue'),
        meta: { title: '登录日志', icon: 'Document' }
      },
      {
        path: '/system-settings',
        component: () => import('@/views/SystemSettings.vue'),
        meta: { title: '系统设置', icon: 'Setting' }
      }
    ]
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior() {
    return { top: 0 } // 路由切换时滚动到顶部
  }
})

// 动态设置页面标题
router.beforeEach((to) => {
  document.title = to.meta.title ? `${to.meta.title} - 管理系统` : '管理系统'
})

export default router